package com.blacktea.behavioralpatterns.mediatorpattern;

import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @description:
 * @author: black tea
 * @date: 2023/3/25 16:44
 */
@Slf4j
@Service
public class UserService implements Colleague {

    private final Mediator mediator;

    public UserService(@Autowired Mediator mediator) {
        mediator.register(StrUtil.lowerFirst(this.getClass().getSimpleName()), this);
        this.mediator = mediator;
    }

    public void updateBorrowInfo(String isbn, String borrower) {
        log.info("user service 用户服务更新借阅信息...");
        send("updateBorrowInfo");
    }

    @Override
    public void send(String message, Object... args) {
        mediator.handleMessage(message, this, args);
    }

    @Override
    public void receive(String message) {
        log.info("用户服务接收到消息：" + message);
    }
}
